<?php
/**
 * +--------------------------------------------------------+
 * @Created by Phpstorm.
 * @Category SocialiteService.php
 * @Depiction
 * @Author hwy
 * @Date 2021/4/6  16:23
 * +--------------------------------------------------------+
 */

namespace App\Services;


use App\Models\User;
use Illuminate\Support\Str;
use Auth;

class SocialiteService extends BaseService
{
    public function __construct()
    {
    }

    public function QqLogin($user)
    {
        $qq_user_id = $user->id;
        $check      = User::where('qq_id', $qq_user_id)->first();
        if (!$check) {
            $user_data = [
                'name'              => 'user_' . Str::random(6),
                'email'             => $user->email,
                'email_verified_at' => null,
                'password'          => bcrypt('blog13456'),
                'remember_token'    => null,
                'nickname'          => $user->nickname,
                'qq_id'             => $user->id,
                'qq_access_token'   => $user->token,
                'qq_refresh_token'  => $user->refreshToken,
                'qq_expires_in'     => $user->expiresIn,
                'qq_nickname'       => $user->nickname,
                'gender_type'       => $user->user['gender_type'],
                'year'              => $user->user['year'],
                'qq_avatar'         => $user->avatar,
                'can_account_login' => 2,
            ];

            $customer = User::create($user_data);
            $check    = User::where('qq_id', $qq_user_id)->first();
        }

        Auth::login($check, true);
        return true;
    }



}
